package cn.edu.gzhmt.order.domain;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import cn.edu.gzhmt.user.domain.User;

/**
 * 订单实体类
 * @author azhuo
 *
 */
public class Order implements Serializable {

	private String oid; // 订单编号id
	private String ostate; // 订单状态
	private Double total; // 订单总价
	private Date time; // 下单时间
	private User user; // 订单所属的用户
	private String uid;
	private String oaddress; // 订单收货地址
	private String odel;

	public Order() {
	}

	public Order(String oid, String ostate) {
		this.oid = oid;
		this.ostate = ostate;
	}

	// 订单下的所有条目
	private List<OrderItem> orderItemList = null;

	public String getOid() {
		return oid;
	}

	public void setOid(String oid) {
		this.oid = oid;
	}

	public String getOstate() {
		return ostate;
	}

	public void setOstate(String ostate) {
		this.ostate = ostate;
	}

	public Double getTotal() {
		/*BigDecimal total = new BigDecimal("0"); // 价格总计，处理double的不精确问题
		// 订单中有商品
		if (orderItemList != null) {
			for (OrderItem orderItem : orderItemList) {
				total.add(new BigDecimal(orderItem.getSubtotal() + ""));
			}
		}
		return total.doubleValue();*/

		if (orderItemList != null) {
			this.total = 0.0;
			for (OrderItem orderItem : orderItemList) {
				this.total += orderItem.getSubtotal();
			}
		}
		
		return this.total;
	}

	public void setTotal(Double total) {
		this.total = total;
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	public User getUser() {
		return user;
	}

	public String getUid() {
		return uid;
	}

	public void setUid(String uid) {
		this.uid = uid;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getOaddress() {
		return oaddress;
	}

	public void setOaddress(String oaddress) {
		this.oaddress = oaddress;
	}

	public List<OrderItem> getOrderItemList() {
		return orderItemList;
	}

	public void setOrderItemList(List<OrderItem> orderItemList) {
		this.orderItemList = orderItemList;
	}

	public String getOdel() {
		return odel;
	}

	public void setOdel(String odel) {
		this.odel = odel;
	}

	@Override
	public String toString() {
		return "Order [oid=" + oid + ", ostate=" + ostate + ", total=" + total
				+ ", time=" + time + ", user=" + user + ", uid=" + uid
				+ ", oaddress=" + oaddress + ", odel=" + odel
				+ ", orderItemList=" + orderItemList + "]";
	}

}
